home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 2.5 KB | 52 lines | [TEXT/GEOL] |
- Item 8265122 25-Oct-90 14:28PDT
-
- From: V0683 Amoco Tech, Eric Berdahl,VAR
-
- To: MACAPP.TECH$ MacApp Technical
- LENOIL Lenoil, Robert
-
- Sub: Re: Auto-Initialized Objects
-
- Robert,
-
- Bravo! I like what I see in your change to MakeNewInstance. Once again, you
- demonstrate that MacApp has the built-in capacity to emulate higher order
- object concepts. Some time ago, the concept of assertions and error handling
- was raised (no pun intended). The resulting conversations showed clearly that
- MacApp already had an assertion mechanism, and that direct language support was
- not neccessary (although it's alway nice to have…).
-
- Now, we see that a constructor mechanism is possible within MacApp via
- MakeNewInstance and TMyObject::Initialize. Reading through your discussion,
- though, I'd like to emphasize one particular point. Constructors (read: the
- Initialize method) is meant to put the object into a known (read: safe) state!
- Many problems beginning C++ programmers have with the constructor mechanism is
- that they try to do things that can fail, and when a failure occurs, they are
- left swinging in the breeze. Learn from the mistakes of others and only do
- default initializations in your constructors (read: Initialize methods)!
-
- Now, I have a devil's advocate question for you. Is the only benefit of your
- change the loss of numerous FailNIL calls after allocation? I grant you that
- constructors are nice, but I still have to call the IMyObject method anyway, so
- why shouldn't I just construct in IMyObject and follow with the initialization?
- Please don't misunderstand, I like what I see, but I'm interested in your
- thoughts for "the next step" in this process.
-
- As a possible answer, I would propose that we gain good object design. That
- is, constructors construct and initializers (read: IMyObject methods)
- initialize. By splitting the two operations into two methods, we gain good
- object definition.
-
- A second possible answer is that this Initialization will also allow TView
- subclasses to be initialized from the appropriate IRes methods, meaning I don't
- have to override IRes and IMyObject (well, you know), only Initialize. Thus,
- we come to an interesting problem. If I need to do non-trivial initialization
- (ie: maybe allocate some memory, etc), IRes must still be overridden as well as
- IMyObject. Questions, questions, questions.
-
- Stirring the soup,
- Eric Berdahl
- Amoco Technology Company
- AppleLink: V0683
-
-